home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13826 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  41 lines

  1. Newsgroups: comp.lang.c
  2. Path: axcdf1.pd.infn.it!LORETI
  3. From: loreti@axcdf1.pd.infn.it (Maurizio Loreti)
  4. Subject: Re: array[index]
  5. X-Nntp-Posting-Host: axcdf1.pd.infn.it
  6. Message-ID: <DpnG4p.3xr@news.cern.ch>
  7. Sender: news@news.cern.ch (USENET News System)
  8. Reply-To: loreti@axcdf1.pd.infn.it
  9. Organization: I.N.F.N. Padova - CDF/CMS VAXcluster
  10. References: <4jiies$3bh@fnord.dfw.net>
  11. Date: Wed, 10 Apr 1996 14:57:59 GMT
  12.  
  13. In article <4jiies$3bh@fnord.dfw.net>, ftlgeuse@dfw.dfw.net (Azazel Diabolus            (aka Fetelgeuse)) writes:
  14. >On my platform's assembly language a[n] is the same as n[a]; is this also 
  15. >valid in C? Does array[index] give the same address as index[array]? I 
  16. >will try this after I post it but I would like to know if this is 
  17. >something defined by the ANSI standard. Thanks,
  18. >Fetelgeuse
  19.  
  20. Checking the FAQ list before posting, you accidentally skipped Q/A
  21. 6.11; here it is:
  22.  
  23. 6.11:    I came across some "joke" code containing the "expression"
  24.     5["abcdef"] .  How can this be legal C?
  25.  
  26. A:    Yes, Virginia, array subscripting is commutative in C.  This
  27.     curious fact follows from the pointer definition of array
  28.     subscripting, namely that a[e] is identical to *((a)+(e)), for
  29.     *any* two expressions a and e, as long as one of them is a
  30.     pointer expression and one is integral.  This unsuspected
  31.     commutativity is often mentioned in C texts as if it were
  32.     something to be proud of, but it finds no useful application
  33.     outside of the Obfuscated C Contest (see question 20.36).
  34.  
  35.     References: Rationale Sec. 3.3.2.1; H&S Sec. 5.4.1 p. 124,
  36.     Sec. 7.4.1 pp. 186-7.
  37.  
  38. --
  39. Maurizio Loreti                       http://mvxpd5.pd.infn.it/wwwcdf/mlo.html
  40. Un. of Padova, Dept. of Physics - Padova, Italy          loreti@padova.infn.it
  41.